<div class="row">
	<div class="col-md-12">
		<form id="fileAddForm" class="form-horizontal" action="${request.contextPath}/system/config/file/add" method="post" onsubmit="return false">
			<div class="box-body" >
				<div class="form-group">
					<label id="fileTitleLabel" for="fileTitle" class="col-sm-1 control-label">标题</label>
					<div class="col-sm-11">
						<input type="text" class="form-control" name="title" id="fileTitle" placeholder="输入文件标题...">
					</div>
				</div>
				<div class="form-group">
					<label id="fileDirLabel" for="fileDir" class="col-sm-1 control-label">路径</label>
					<div class="col-sm-5">
						<input id="fileDir" name="prefixDir"  class="form-control"  type="text" value="${prefixDir}" placeholder="输入路径..."/>
					</div>
					<label id="sysFileTypeLabel" for="sysFileType" class="col-sm-1  control-label">类型</label>
					<div class="col-sm-5">
						<select class="form-control" id="sysFileType" name="type"   style="width: 100%;"  placeholder="选择文件类型...">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="fileSeqLabel" for="fileSeq" class="col-sm-1  control-label">排序号</label>
					<div class="col-sm-5">
						<input type="text" class="form-control" name="seq" id="fileSeq" type="number" placeholder="输入排序号...">
					</div>
					<label id="sysFileStatusLabel" for="sysFileStatus" class="col-sm-1  control-label">状态</label>
					<div class="col-sm-5">
						<select class="form-control" id="sysFileStatus"  name="status" style="width: 100%;" placeholder="选择状态...">
						</select>
					</div>
				</div>
				<div class="form-group">
					<label id="fileLabel" for="file" class="col-sm-1 control-label">上传</label>
					<div class="col-sm-11">
						<input id="file" type="file" name="file"  />
					</div>
				</div>
				<div class="form-group">
					<label id="fileDescriptionLabel" class="col-sm-1 control-label" >描述</label>
					<div class="col-sm-11">
						<input type="text" class="form-control" name="description" id="fileDescription" placeholder="输入描述...">
					</div>
				</div>
				<div class="form-group">
					<label id="fileRemarkLabel" class="col-sm-1 control-label">备注</label>
					<div class="col-sm-11">
						<input type="text" class="form-control" name="remark" id="fileRemark" placeholder="输入备注...">
					</div>
				</div>
				<div class="error-message text-center" id="fileAddFormErrorMsgContainer">
					<span class="error-icon"></span>
					<span id="fileAddFormErrorMsg" class="error-msg" ></span>
				</div>
			</div>
			<div class="box-body">
				<div class="text-center">
					<button type="submit" class="btn btn-primary btn-sm" ><i class="fa fa-save"></i> 保存</button>
					<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 取消</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script src="${request.contextPath}/static/oms/default/plugins/jQuery/jquery.form.js"></script>

<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
    $form.ajaxSubmit({
        //定义返回JSON数据，还包括xml和script格式
        dataType:'json',
        url:form.action,
        success: function(result) {
            //提交成功后调用
            if (result.success) {
                $("#lgModal").modal('hide');
                alertMsg(result.message,"success");
                fileReload();
            } else {
                $form.find(".error-msg").show();
                $form.find(".error-msg").html(result.message);
            }
        }
    });
}

$(function() {

    $("#sysFileType").select2({
        data: FileTypeStore
    });
    $("#sysFileStatus").select2({
        data: StatusStore
    });

	$fileAddForm = $("#fileAddForm");
	$fileAddForm.validate({
		rules: {
			file: {
				required: true
			},
			seq: {
				required: true
			}
		},
		messages: {
            file:{
				required:"文件不能为空！"
			},
			seq: {
				required: "排序号不能为空！"
			}
		},
		submitHandler:ajaxSubmit,
		errorLabelContainer:"#fileAddFormErrorMsgContainer",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$fileAddForm.find(".error-msg").html(errorList[0].message);
			}else{
				$fileAddForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>